/**
 * Created by JasonZ on 2017/3/28.
 */
function initChartByAjax(url,Func1,Func2,Func3,Func4,Func5) {
    $.ajax({
        url:url,
        type:'get',
        dataType:'json',
        success:function (data) {
            if(Func1) {
                Func1(data);
            }
            if(Func2) {
                Func2(data);
            }
            if(Func3) {
                Func3(data);
            }
            if(Func4) {
                Func4(data);
            }
            if(Func5) {
                Func5(data);
            }
        }
    });
}

function initValueByAjax(url,Func) {
    $.ajax({
        url:url,
        type:'get',
        dataType:'json',
        success:function (data) {
            Func(data);
        }
    });
}

function getArrayMapTotal(array) {
    var total = 0;
    for(var i=0;i<array.length;i++) {
        total += parseInt(array[i].value);
    }
    return total;
}

//得到万级单位
function getArray(array){
	var num;
	var array1 = [];
	for(var i=0;i<array.length;i++){
		num = (parseInt(array[i].value)/10000).toFixed(2);
		array1.push(num);
	}
	return array1;
}

function parseToWan1(value) {
    return (parseInt(value) / 10000).toFixed(1)+"万";
}

function parseToWan2(value) {
    return (parseInt(value) / 10000).toFixed(2)+"万";
}

function calRate(value,total) {
    return parseFloat(value*100/total).toFixed(1)+"%"
}

function getArrayTotal(array) {
    var total = 0;
    for(var i=0;i<array.length;i++) {
        total += parseInt(array[i]);
    }
    return total;
}

function setChartTextWhite(chart) {
    var option = {
        legend: {
            textStyle:{
                color:'#fff'
            }
        },
        xAxis:[
            {
                axisLine:{
                    lineStyle:{
                        color:'#fff'
                    },
                    axisLabel:{
                        textStyle:{
                            color:'#fff'
                        }
                    }
                }
            }
        ],
        yAxis:[
            {
                axisLine:{
                    lineStyle:{
                        color:'#fff'
                    }
                },
                axisLabel:{
                    textStyle:{
                        color:'#fff'
                    }
                }

            }
        ]
    };
    chart.setOption(option);
}

function initRknlChart(data) {
	// var data1 = data.rkgk;

    var data1 = [
        {
            value:1424598,
            name:'未成年'
        },
        {
            value:7447789,
            name:'工作段'
        },
        {
            value:1595867,
            name:'老龄段'
        }
    ];
    var rknlChart = echarts.init(document.getElementById('rknlChart'));

    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{c}<br>{d}%",
        },
        legend: {
            orient: 'vertical',
            x: "75%",
            data:['未成年','工作段','老龄段'],
            textStyle:{
                color:'white',
                fontSize:20
            },
            itemGap:30,
            top:120
        },
        series: [
            {
                name:'人口比例',
                type:'pie',
                radius: ['30%', '70%'],
                center:["35%","50%"],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: true,
                        formatter: function (params) {
                            return parseToWan1(params.value)+"\n"+params.percent+"%";
                        },
                        position: 'outside',
                        textStyle:{
                            color:'white',
                            fontSize:18
                        } 
                    }
                },
                labelLine: {
                    normal: {
                        show: false,
                        length:10
                    }
                },
                data:data1
            }
        ],
        // color:['rgba(39,292,255,0.7)','#cb64ec','#e9744b']
        color:['rgba(39,232,255,0.7)','rgba(203,100,236,0.7)','rgba(233,116,75,0.7)']
    };

    // 使用刚指定的配置项和数据显示图表。
    rknlChart.setOption(option);
}

function initRkjztChart() {
    // var rkjzt = data.rkjzt;
    // var data1 = rkjzt[0];
    // var data2 = rkjzt[1];
    var data1 = [142661, 89401, 301025, 1006502, 1105662, 1881653, 232598,170827,50149];
    var data2 = [-154549, -96851, -326111, -1090377, -1197801, -2038485, -251982,-185062,-54329];

//     var data1 = [];
//     var data2 = [];
    var rkjztChart = echarts.init(document.getElementById('rkjztChart'));
    var option = {
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        legend: {
            data:['男', '女'],
            textStyle:{
                color:'#fff'
            },
            y:30
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '15%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'value',
                name:'人口数量',
                nameLocation:'middle',
                nameGap:40,
                nameTextStyle:{
                    fontSize:20
                },
                max:3000000,
                axisLabel:{
                    formatter:function (value){
                        return Math.abs(value);
                    },
                    textStyle:{
                        color:'#fff',
                        fontSize:18
                    }

                },
                splitLine:{
                    show:false
                },
                axisLine:{
                    lineStyle:{
                        color:'#fff'
                    }
                }
            }
        ],
        yAxis : [
            {
                type : 'category',
                axisTick : {show: false},
                data : ['0-3','4-5','7-14','15-28','29-40','41-65','66-72','73-84','85岁以上'],
                axisLabel:{
                    textStyle:{
                        color:'#fff',
                        fontSize:14

                    }
                }
            },
            {
                type : 'category',
                axisTick : {show: false},
                data : ['0-3','4-5','7-14','15-28','29-40','41-65','66-72','73-84','85岁以上'],
                axisLabel:{
                    textStyle:{
                        color:'#fff',
                        fontSize:14
                    }
                }
            }
        ],
        series : [
            {
                name:'女',
                type:'bar',
                stack: '总量',
                data:data1
            },
            {
                name:'男',
                type:'bar',
                stack: '总量',
                data:data2
            }
        ],
        // color:['#e94b9d','#1779b4']
        color:['rgba(233,75,156,0.7)','rgba(23,121,180,0.7)']
    };
    rkjztChart.setOption(option);
}

function initRkzzqkChart() {
    var data1 = [9306512, 9280073, 9426477, 9488751, 9597712, 9661522, 9742223,9774894,9769244,9772519,9771747,9745761];
    var rkzzqkChart = echarts.init(document.getElementById('rkzzqkChart'));
    var option = {

        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            height:'85%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                boundaryGap : true,
                data : ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],

            }
        ],
        yAxis : [
            {
                type : 'value',
                splitLine:{
                    show:true,
                    lineStyle:{
                        color:'rgba(255, 255, 255, 0.2)'
                    }
                },
                min:9200000
            }
        ],
        series : [
            {
                name:'',
                type:'bar',
                barWidth:40,
                data:data1
            }
        ],
        // color:['#27e8ff']
        color:['rgba(39,232,255,0.7)']
    };
    rkzzqkChart.setOption(option);
    setChartTextWhite(rkzzqkChart);
}

function initRkzzzbChart() {
    var data1 = [
        {value:3662+21694, name:'江北区'},
        {value:9708+32051, name:'北仑区'},
        {value:7112+33710, name:'镇海区'},
        {value:16210+109402, name:'鄞州区'},
        {value:1394+26237, name:'余姚市'},
        {value:1943+66944, name:'慈溪市'},
        {value:573+9040, name:'奉化区'},
        {value:949+11239, name:'象山县'},
        {value:2264+21682, name:'宁海县'},
        {value:17838+12189, name:'高新区'},
        {value:213+6689, name:'东钱湖区'},
        {value:938+20847, name:'杭州湾新区'}
    ];
    var rkzzzbChart = echarts.init(document.getElementById('rkzzzbChart'));
    var option = {
        backgroundColor: 'transparent',

        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        series : [
            {
                name:'',
                type:'pie',
                radius : '68%',
                center: ['50%', '50%'],
                data:data1.sort(function (a, b) { return a.value - b.value}),
                roseType: 'angle',
                startAngle:70,
                label: {
                    normal: {
                        textStyle: {
                            color: '#fff',
                            fontSize:20
                        },
                        formatter:'{b}'
                    }
                },
                labelLine: {
                    show:false
                },
                itemStyle: {
                    normal: {
                        // color: '#f9d34c',
                        color: 'rgba(249,211,76,0.7)',
                        shadowBlur: 200,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    rkzzzbChart.setOption(option);
}

function initCsswChart() {
    // var data1 = [11, 11, 15, 13, 12, 13, 10,11, 11, 15, 13, 12];
    // var data2 = [9, 12, 16, 14, 13, 14, 11,12, 13, 17, 11, 9];

    var data1 = [287, 285, 206, 1, 159, 179, 239,190, 0, 255, 600, 6];
    var data2 = [145, 164, 99, 20, 90, 122, 116,116, 0, 197, 293, 1];
    var csswChart = echarts.init(document.getElementById('csswChart'));
    var option = {
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            orient:'vertical',
            data:['出生率','死亡率'],
            x:680,
            y:150,
            textStyle:{
                color:'#fff'
            }

        },
        grid: {
            left: '3%',
            bottom: '10%',
            containLabel: true,
            width:'80%'
        },
        xAxis:  {
            type: 'category',
            boundaryGap: false,
            data: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
            axisLine:{
                lineStyle:{
                    color:'#fff'
                }
            }
        },
        yAxis: {
            type: 'value',
            name:'万分率',
            axisLabel: {
                formatter: function (value) {
                    return parseFloat(value*10000/5820397).toFixed(1);
                },
                textStyle:'#fff'
            },
            axisLine:{
                lineStyle:{
                    color:'#fff'
                }
            },
            splitLine:{
                lineStyle:{
                    color:'#555'
                }
            }
        },
        series: [
            {
                name:'出生率',
                type:'line',
                data:data1,
                symbol:'circle'
            },
            {
                name:'死亡率',
                type:'line',
                data:data2,
                symbol:'rect'
            }
        ],
        color:['#1779b4','#91c03f']
    };
    csswChart.setOption(option);
}

function initPeopleCountChart(data) {
    // var data1 = data.rk;
    var data1 = [{value:5905074, name:'户籍'},
                {value:3970724, name:'外来'},
                {value:134, name:'境外'}
                ];
    // 基于准备好的dom，初始化echarts实例
    // var data2 = getArray(data1);
    $("#peopleTotal").text(parseToWan1(getArrayMapTotal(data1)));
    var peopleCountChart = echarts.init(document.getElementById('peopleCountChart'));

    // 指定图表的配置项和数据
    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{c}<br>{d}%",
        },
        legend: {
            orient: 'vertical',
            x: "80%",
            data:['户籍','外来','境外'],
            textStyle:{
                color:'white',
                fontSize:20
            },
            itemGap:30,
            top:150
        },
        series: [
            {
                name:'人口比例',
                type:'pie',
                radius: ['30%', '60%'],
                center:["40%","60%"],
                avoidLabelOverlap: false,
                startAngle:40,
                minAngle:10,
                label: {
                    normal: {
                        formatter: function (params) {
                            return parseToWan2(params.value)+"\n"+params.percent+"%";
                        },
                        position: 'outside',
                        textStyle:{
                            color:'white',
                            fontSize:18
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false,
                        length:10
                    }
                },
                data:data1
            }
        ],
        // color:['#1779b4','#f9d34c','#e94b9d']
        color:['rgba(23,121,180,0.7)','rgba(249,211,76,0.7)','rgba(233,75,157,0.7)']
    };

    // 使用刚指定的配置项和数据显示图表。
    peopleCountChart.setOption(option);
}

function initImportanceCountChart(data) {
    var data1 = data.dxry;
    // var data1 = [1,2,3];//骨干、服务、管控
    var total = getArrayTotal(data1);
    $("#importanceCount").text(parseToWan1(total));
    var importanceCountChart = echarts.init(document.getElementById('importanceCountChart'));
    var option = {
        color: ['#3398DB'],
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: '1%',
            right: '9%',
            bottom: '20%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                data : [{
                    value:'骨干',
                    textStyle:{
                        color:'white',
                        fontSize:20
                    }
                }, {
                    value:'服务',
                    textStyle:{
                        color:'white',
                        fontSize:20
                    }
                }, {
                    value:'管控',
                    textStyle:{
                        color:'white',
                        fontSize:20
                    }
                }],
                axisTick: {
                    show:false
                },
                axisLine:{
                    lineStyle:{
                        color:'#27e8ff'
                    }
                }
            }
        ],
        yAxis : [
            {
                type : 'value',
                axisLabel:{
                    show:false
                },
                axisLine:{
                    show:false
                },
                splitLine:{
                    show:false
                },
                axisTick:{
                    show:false
                }
            }
        ],
        series : [
            {
                name:'',
                type:'bar',
                barWidth: '40%',
                data:data1,
                itemStyle: {
                    //通常情况下：
                    normal:{
                        //每个柱子的颜色即为colorList数组里的每一项，如果柱子数目多于colorList的长度，则柱子颜色循环使用该数组
                        color: function (params){
                            // var colorList = ['#27e8ff','#cb64ec','#e94b4b'];
                            var colorList = ['rgba(39,232,255,0.7)','rgba(203,100,236,0.7)','rgba(233,75,75,0.7)'];
                            return colorList[params.dataIndex];
                        }
                    },
                    //鼠标悬停时：
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                },
                label:{
                    normal:{
                        show:true,
                        position:'outside',
                        formatter:function (params) {
                            return parseToWan1(params.value)+'\n'+calRate(params.value,total);
                        },
                        textStyle:{
                            fontSize:20
                        }
                    }
                }
            }
        ]
    };
    importanceCountChart.setOption(option);
}

function initKeyPlaceChart(data) {
    var data1 = data.sszt2;
    var data2 = [];
    //数据为0的不显示
    for(var i=0;i<data1.length;i++) {
        if(data1[i].value) {
            data2.push(data1[i]);
        }
    }
    // var data1=[
    //     {value:511, name:'学校'},
    //     {value:12642, name:'消防'}
    // ];
    $("#keyPlaceTotal").text(getArrayMapTotal(data1));
    var keyPlaceChart = echarts.init(document.getElementById('keyPlaceChart'));
    var option = {
        backgroundColor: 'transparent',

        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },

        series : [
            {
                name:'',
                type:'pie',
                radius : '55%',
                center: ['50%', '50%'],
                minAngle:30,
                data:data2,
                label: {
                    normal: {
                        textStyle: {
                            color: '#fff',
                            fontSize:20
                        },
                        formatter:'{b}\n{c}'
                    }
                },
                labelLine: {
                    normal:{
                        show:false,
                        length:20,
                        length2:0
                    }
                }
            }
        ],
        color:['#4d59cc','#27e8ff']
    };
    keyPlaceChart.setOption(option);
}

function initHouseChart(data) {
    var data1 = data.fw;
    // var data2 = data.fwlx;
    // var data1= [
    //     {value:335, name:'房屋   '},
    //     {value:679, name:'出租房'},
    //     {value:1548, name:'危房'}
    // ];
    var data2 = [
        {value:335, name:'国有产权'},
        {value:310, name:'集体产权'},
        {value:234, name:'其他'}
    ];
    var houseChart = echarts.init(document.getElementById('houseChart'));
    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            orient: 'horizontal',
            x: 110,
            y: 420,
            data:['房屋','出租房','危房','国有产权','集体产权','其他'],
            width:400,
            itemGap:30,
            textStyle:{
                color:'#fff',
                fontSize:20
            }
        },
        series: [
            {
                name:'',
                type:'pie',
                selectedMode: 'single',
                radius: ['40%', '55%'],
                minAngle:10,
                startAngle:200,
                label: {
                    normal: {
                        position: 'outSide',
                        formatter:"{b}\n{d}%",
                        textStyle:{
                            color:'#fff',
                            fontSize:20
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data:data1,
                center:["50%","40%"]
            },
            {
                name:'',
                type:'pie',
                radius: ['0', '30%'],

                data:data2,
                center:["50%","40%"],
                label: {
                    normal: {
                        position: 'inner',
                        formatter:"{d}%",
                        textStyle:{
                            fontSize:18,
                            color:'#000'
                        }
                    }

                },
                labelLine: {
                    normal: {
                        show: false
                    }
                }

            }
        ],
        // color:['#4d59cd','#27e8ff','#cb64ec','#1779b4','#e94b9d','#f9d34c'],
        color:['#4d59cd','#27e8ff','rgba(203,100,236,0.7)','#1779b4','rgba(23,75,157,0.7)','#f9d34c']

    };
    houseChart.setOption(option);
}

function initDatabasePie(data){
	var data1 = data.zflx;
    /*var data1 = [
        {
            value:335555,
            name:'人口'
        },
        {
            value:3105555,
            name:'企业'
        }
    ];*/
	
    var databasePie = echarts.init(document.getElementById('databasePie'));

    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{c}<br>{d}%",
        },
        series: [
            {
                name:'走访比例',
                type:'pie',
                radius: ['40%', '60%'],
                center:["50%","50%"],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: true,
                        formatter: "{b}\n{d}%",
                        position: 'outside',
                        textStyle:{
                            color:'white',
                            fontSize:16
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: true,
                        length:0,
                        length2:0
                    }
                },
                data:data1
            }
        ],
        // color:['#e94b9d','#27e8ff','#4d59cc']
        color:['rgba(233,75,157,0.7)','#27e8ff','#4d59cc']
    };

    databasePie.setOption(option);

}

function initImportantPeoplePie(data){
	var data1 = data.zfzl;
    /*var data1 = [
        {value:335, name:'骨干对象'},
        {value:310, name:'管控对象'},
        {value:274, name:'服务对象'}
    ];*/
    $("#inportantCount").text(getArrayMapTotal(data1));
    var importantPie = echarts.init(document.getElementById('importantPie'));

    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{c}<br>{d}%",
        },
        series: [
            {
                name:'走访比例',
                type:'pie',
                radius: [0, '60%'],
                center:["50%","50%"],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: true,
                        formatter: "{b}\n{d}%",
                        position: 'outside',
                        textStyle:{
                            color:'white',
                            fontSize:16
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: true,
                        length:0,
                        length2:0
                    }
                },
                data:data1
            }
        ],
        // color:['#e94b9d','#27e8ff','#4d59cc']
        color:['rgba(233,75,157,0.7)','#27e8ff','#4d59cc']
    };

    importantPie.setOption(option);

}

function initHyzbChart() {
    var data1 = [{value:335, name:'行业1'},
        {value:310, name:'行业2'},
        {value:310, name:'行业3'},
        {value:310, name:'行业4'},
        {value:134, name:'行业5'}
    ];
    var chart = echarts.init(document.getElementById(''));

    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{c}",
        },
        series: [
            {
                name:'',
                type:'pie',
                radius: ['30%', '70%'],
                center:["35%","60%"],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        formatter: "{b}\n{d}%",
                        position: 'outside',
                        textStyle:{
                            color:'white',
                            fontSize:18
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false,
                        length:0
                    }
                },
                data:data1
            }
        ],
        color:['#e9744b','#f9d34c','#91c03f','#38b8a4','#e94b4b']
    };

    chart.setOption(option);
}

function initSsztChart() {
    var orgName = ['余姚', '慈溪', '江北', '镇海', '北仑', '鄞州', '奉化',
        '海宁', '象山', '江东'];
    var data1 = [320, 332, 301, 334, 390, 330, 320];
    var data2 = [320, 332, 301, 334, 390, 330, 320];
    var data3 = [320, 332, 301, 334, 390, 330, 320];
    var chart = echarts.init(document.getElementById(''));
    var option = {
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                data :['余姚', '慈溪', '江北', '镇海', '北仑', '鄞州', '奉化',
                    '海宁', '象山', '江东']
            }
        ],
        yAxis : [
            {
                type : 'value'
            }
        ],
        series : [
            {
                name:'直接访问',
                type:'bar',
                stack: '商事主体',
                data:[320, 332, 301, 334, 390, 330, 320]
            },
            {
                name:'邮件营销',
                type:'bar',
                stack: '商事主体',
                data:[120, 132, 101, 134, 90, 230, 210]
            },
            {
                name:'联盟广告',
                type:'bar',
                stack: '商事主体',
                data:[220, 182, 191, 234, 290, 330, 310]
            }
        ],
        color:['#1779b4','#e94b9d','#f9d34c']
    };
    chart.setOption(option);
}

function initSsztzbChart() {
    var data1 = [{value:335, name:'企业'},
        {value:310, name:'机关'},
        {value:134, name:'组织'}
    ];
    var chart = echarts.init(document.getElementById('chart'));

    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{c}<br>{d}%",
        },
        legend: {
            orient: 'vertical',
            x: "75%",
            data:['企业','机关','组织'],
            textStyle:{
                color:'white',
                fontSize:20
            },
            itemGap:30,
            top:150
        },
        series: [
            {
                name:'人口比例',
                type:'pie',
                radius: ['30%', '70%'],
                center:["35%","60%"],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        formatter: "{c}\n{d}%",
                        position: 'outside',
                        textStyle:{
                            color:'white',
                            fontSize:18
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false,
                        length:0
                    }
                },
                data:data1
            }
        ],
        color:['#1779b4','#f9d34c','#e94b9d']
    };

    chart.setOption(option);
}


//商事主体行业排名饼图
function initHyzbPie(data) {
    //var data1 = data.rk;
     var data1 = [{value:335, name:'行业一'},
                 {value:310, name:'行业二'},
                 {value:134, name:'行业三'},
                 {value:134, name:'行业四'},
                 {value:134, name:'行业五'}
                 ];
    // 基于准备好的dom，初始化echarts实例
    var hyzb = echarts.init(document.getElementById('hyzb'));

    // 指定图表的配置项和数据
    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{c}<br>{d}%",
        },
        legend: {
            orient: 'vertical',
            x: "80%",
            data:[],
            textStyle:{
                color:'white',
                fontSize:20
            },
            itemGap:30,
            top:150
        },
        series: [
            {
                name:'人口比例',
                type:'pie',
                radius: ['30%', '60%'],
                center:["50%","50%"],
                avoidLabelOverlap: false,
                startAngle:0,
                label: {
                    normal: {
                        formatter: "{b}\n{d}%",
                        position: 'outside',
                        textStyle:{
                            color:'white',
                            fontSize:18
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: true,
                        length:15,
                        length2:55
                    }
                },
                data:data1
            }
        ],
        color:['#1779b4','#f9d34c','#e94b9d']
    };

    // 使用刚指定的配置项和数据显示图表。
    hyzb.setOption(option);
}

function initHeatMap(datas){
    var importantInterviewMap = echarts.init(document.getElementById('importantInterviewMap'));
    
    var data = datas.zdzffb;
    var orgName = datas.orgNames;
    var typeName = datas.typeNames;
    /*var orgName = ["海曙区","江北区","北仑区","镇海区","鄞州区","余姚市","慈溪市","奉化区","象山县","宁海县","高新区","东钱湖区","保税区"];*/
    //var typeName = ['骨干', '管控', '服务'];

    /*var data = [[0,0,0],[0,1,0],[0,2,0],[0,3,0],[0,4,0],[0,5,0],
        [0,6,0],[0,7,6],[0,8,21],[0,9,36],[0,10,36],[0,11,36],[1,0,7],[1,10,36],[1,11,36],[1,1,30],[1,2,4],
        [1,3,6],[1,4,8],[1,5,6],[1,6,9],[1,7,30],[1,8,2],[1,9,8],[2,0,150],
        [2,1,1],[2,2,10],[2,3,10],[2,4,10],[2,5,3],[2,6,5],[2,7,8],[2,10,36],[2,11,36],[2,8,9],
        [2,9,1]];*/

    data = data.map(function (item) {
        return [item[1], item[0], item[2] || '-'];
    });

    var option = {
        tooltip: {
            position: 'top'
        },
        animation: true,
        grid: {
            height: '75%',
            y: '10%',
            x:'12%',
            width:'75%'
        },
        xAxis: {
            type: 'category',
            data: orgName,
            splitArea: {
                show: true
            },
            axisLabel:{
                show:true,
                interval:0,
                rotate:45,
                margin:2,
                textStyle: {
                    color: '#fff'
                }
            }

        },
        yAxis: {
            type: 'category',
            data: typeName,
            splitArea: {
                show: true
            },
            axisLabel:{
                textStyle:{
                    fontSize:20
                }
            }
        },

        visualMap: {
            min: 0,
            max: 20000,
            calculable: true,
            orient: 'vertical',
            left: '89%',
            top: '43%',
            inRange:{
                color:['transparent','#27e8ff'],
            },
            textStyle:{
                color:'#fff'
            }

        },
        series: [{
            name: '',
            type: 'heatmap',
            data: data,
            label: {
                normal: {
                    show: true,
                    formatter:function(params){
                    	var str = params.value[2];
                    	if(params.value[2] == '0'){
                    		str = '0';
                    	}
                    	return str;
                    }
                }
            },
            dataLabels: {
                enabled: true
            },
            itemStyle: {
                normal:{
                    color:'#27e8ff'
                },
                emphasis: {
                    shadowBlur: 10,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }]

    };
    importantInterviewMap.setOption(option);
    setChartTextWhite(importantInterviewMap);
}

function initThreeTypePeoplePie(data){
	var data1 = data.zfzl;
	var ggdx = data.main;
	var gkdx = data.manage;
	var fwdx = data.service;

	//为0的数据不显示
    var ggdx1=[];
    var gkdx1=[];
    var fwdx1=[];
    var i=0;
    for(;i<ggdx.length;i++) {
        if(ggdx[i].value){
            ggdx1.push(ggdx[i]);
        }
    }
    for(i=0;i<gkdx.length;i++) {
        if(gkdx[i].value){
            gkdx1.push(gkdx[i]);
        }
    }
    for(i=0;i<fwdx.length;i++) {
        if(fwdx[i].value){
            fwdx1.push(fwdx[i]);
        }
    }

    //var data1 = [{name:'服务对象',value:15},{name:'骨干对象',value:15},{name:'管控对象',value:15}];
    /*var data2 = [{name:'重病卧床老人',value:5},{name:'孤寡空巢老人',value:5},{name:'低保困难对象',value:5},{name:'低保困难对象',value:5},
        {name:'人大代表',value:5},{name:'政协委员',value:3},{name:'村居民代表',value:2},
        {name:'矫正人员',value:5},{name:'重点青少年',value:5},{name:'信访人员',value:5}];*/
    /*var fwdx = [{name:'重病卧床老人',value:5},{name:'孤寡空巢老人',value:5},{name:'低保困难对象',value:5}];
    var ggdx = [{name:'人大代表',value:5},{name:'政协委员',value:5},{name:'村居民代表',value:5}];
    var gkdx = [{name:'矫正人员',value:5},{name:'重点青少年',value:5},{name:'信访人员',value:5}];*/
    var colors = ['#f9d34c','#1779b4','rgba(233,75,157,0.7)'];
    var colorList = [];
    var data2 = [];
    if(ggdx1){
    	for(i=0;i<ggdx1.length;i++){
    		colorList.push(colors[0]);
    		data2.push(ggdx1[i]);
    	}
    }

    if(gkdx1){
    	for(i=0;i<gkdx1.length;i++){
    		colorList.push(colors[1]);
    		data2.push(gkdx1[i]);
    	}
    }

    if(fwdx1){
    	for(i=0;i<fwdx1.length;i++){
    		colorList.push(colors[2]);
    		data2.push(fwdx1[i]);
    	}
    }


    var bottomPie = echarts.init(document.getElementById('bottomPie'));
    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{a} {b}: {c} ({d}%)"
        },
        series: [
            {
                name:'服务骨干管控',
                type:'pie',
                selectedMode: 'single',
                radius: [0, '40%'],
                startAngle:-200,
                label: {
                    normal: {
                        position: 'inner'
                    }
                },
                labelLine: {
                    normal: {
                        show: false,
                        length:0

                    }
                },
                itemStyle:{
                    normal:{
                        borderColor:"#fff"
                    }
                }
            },
            {
                name:'对象走访',
                type:'pie',
                radius: ['40%', '55%'],
                startAngle:-200,

                label: {
                    normal: {
                        textStyle:{
                            color:'#fff'
                        },
                        formatter:'{b}\n{d}%'
                    }
                },
                labelLine: {
                    normal: {
                        show:false,
                        length:0
                    }
                },
                itemStyle:{
                    normal:{
                        borderColor:"#fff",
                        color: function (params){
                            return colorList[params.dataIndex];
                        }
                    }
                }
            }
        ],
        color:colors
    };
    bottomPie.setOption(option);
    bottomPie.setOption({series:[{data:data1},{data:data2}]});
}
